package com.tedu.supermarket_01.controller;

import com.tedu.supermarket_01.pojo.User;
import com.tedu.supermarket_01.services.UserServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * 用户模块  登录、注册。。。。。。。
 */
@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    UserServices userServices;

    /**
     * 用户登录
     * @param user
     * @return
     */
    @RequestMapping("dologin")
    public String login(User user){
        System.out.println(user);
        //调用用户模块的服务接口，实现用户登录
        

        return "frame";

    }
    /**
     * 用户管理---显示用户列表信息
     * @return
     */
    @RequestMapping("userlist.html")
    public String userlist(Model model){

        List<User> userByPageSize = userServices.getUserByPageSize(0,0);
        model.addAttribute("userList",userByPageSize);
        System.out.println(userByPageSize);
        return "userlist";

    }

    /**
     * 用户退出
     * @return
     */
    @RequestMapping("/logout.html")
    public String logout(HttpSession httpSession){
        //session
        httpSession.removeAttribute("userSession");
        return "login";

    }


}

